/**
 * Copyright 2011 Declan.z
 */
package com.mail163.email.location;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;

import com.mail163.email.Logs;

public class WifiInfoManager {
    
    WifiManager wm;
    
    public WifiInfoManager(){}
    
    public ArrayList<WifiInfo> getWifiInfo(Context context){
        wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wm.isWifiEnabled()) {
            wm.startScan();
            ArrayList<WifiInfo> wifi = new ArrayList<WifiInfo>();
            List<ScanResult> results = wm.getScanResults();
            if (results != null) {
                for (ScanResult result : results) {
                    WifiInfo info = new WifiInfo();
                    info.mac = result.BSSID;
                    info.ssid = result.SSID;
                    info.strength = result.level + "";
                    wifi.add(info);
                    Logs.v(Logs.LOG_TAG, "result.BSSID :"+result.BSSID+" result.SSID :"+result.SSID+" result.level :"+result.level);
                }
            }
            return wifi;
        } else {
            return null;
        }
    }
}
